import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * TODO
 *
 * @author gaoxiang
 * @date 2021/7/270:27
 */
public class Send{
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建链接工厂对象
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("121.41.192.69");//设置RabbitMQ的主机IP
        factory.setPort(5672);//设置RabbitMQ的端口号
        factory.setUsername("guest");//设置访问用户名
        factory.setPassword("guest");//设置访问密码
//        Connection connection=null;//定义链接对象
//        Channel channel=null;//定义通道对象
        Connection connection=factory.newConnection();//实例化链接对象
        Channel channel=connection.createChannel();//实例化通道对象
        String message ="Hello World!";
//创建队列 ，名字为myQueue
        channel.queueDeclare("Queue_2", true, false, false, null);
//发送消息到指定队列
        for(int i=0;i<30;i++){
            channel.basicPublish("","Queue_2",null,(message+i).getBytes("UTF-8"));
            System.out.println("消息发送成功"+i);
        }

        channel.close();
        connection.close();
    }
}
